local skel = fk.CreateSkill {
  name = "emo__qinqing",
}

Fk:loadTranslationTable{
  ["emo__qinqing"] = "寝情",
  [":emo__qinqing"] = "每轮限一次，一号位受到伤害后，你可令其体力回复至上限，其下回合开始，其视为对自己使用等量张无伤害来源的【杀】。",

  ["@emo__qinqing"] = "寝情",
  ["#emo__qinqing-ask"] = "寝情：你可以令 %src 回复体力至上限，其下回合开始，视为被使用等量张【杀】",

  ["$emo__qinqing1"] = "卑职愿为陛下分忧。",
  ["$emo__qinqing2"] = "陛下已安寝，休要打扰。",
}

skel:addEffect(fk.Damaged, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target.seat == 1 and not target.dead and target:isWounded()
    and player:usedSkillTimes(skel.name, Player.HistoryRound) == 0
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {
      skill_name = skel.name, prompt = "#emo__qinqing-ask:" .. target.id
    }) then
      event:setCostData(self, { tos = { target } })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local num = target.maxHp - target.hp
    room:addPlayerMark(target, "@emo__qinqing", num)
    room:recover { num = num, skillName = skel.name, who = target, recoverBy = player }
  end,
})

skel:addEffect(fk.TurnStart, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return player == target and player:getMark("@emo__qinqing") > 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local num = player:getMark("@emo__qinqing")
    room:setPlayerMark(target, "@emo__qinqing", 0)
    for i = 1, num do
      if player.dead then break end
      local card = Fk:cloneCard("slash")
      card.skillName = skel.name
      if player:isProhibited(player, card) then break end
      room:useCard{
        from = player, tos = {player}, card = card, extraUse = true,
      }
    end
  end,
})

skel:addEffect(fk.PreDamage, {
  can_refresh = function (self, event, target, player, data)
    return target == data.to and data.card and table.contains(data.card.skillNames, skel.name)
  end,
  on_refresh = function (self, event, target, player, data)
    data.from = nil
  end,
})

return skel
